﻿/******************************************************************************
* File description: SpeechMod.qml
* Function: 语音模块页面
* Current Version: 1.1
* Author: 陈乃瑞
* Date: 2025-07-01
*  -----
*  Copyright by 博坤生物 .
 *****************************************************************************/
import QtQuick 2.0
import "../components"
Rectangle {
    width: parent.width
    height: parent.height
    radius: 12
    color: "white"
    Connections{
        target: CSignal
        onVoiceAssistant:{     // 通信状态
            if(status===0){
                speechModToast.show("连接成功",0);
            }
            else{
                speechModToast.show("连接失败",1)
            }
        }
    }
    onVisibleChanged: {
        if(visible){
            serialPort.model = CGetMessageInterface.getSerialPort()
        }
    }

    Toast{
        id: speechModToast
        x: (parent.width-width) * 0.5
        y: 10*dp
    }
    Item{
        y: 140*dp
        anchors.horizontalCenter: parent.horizontalCenter
        width: 440*dp; height: parent.height-140*dp
        Column{
            anchors.fill: parent
            spacing: 20*dp
            CustomComboBox{
                id:serialPort
                x:(parent.width-width)/2
                y:140*dp
                titleWidth: 100*dp
                editWidth: 340*dp
                title: "语音模块选择"
                model: CGetMessageInterface.getSerialPort()
                onPopupVisibleChanged: {
                    model = CGetMessageInterface.getSerialPort()
                }
            }
            Row{
                height: 40*dp
                spacing: 5*dp
                Text {
//                    x:parent.width/2-120*dp
                    width: 100*dp
                    text: qsTr("是  否  开  启")
                    font.pixelSize: config.fontsize
                }
                CustomSwitchButton{
//                    x:parent.width/2-50*dp
                    width: 40*dp
                    height: 25*dp
                    id: button_autoExport
                    checked: true
                    CustomTooltip{
                        visible: parent.isHovered
                        text: "是否默认"
                    }
                    onClicked: {
                        if(checked){
                            textv.text="否"
                            checked=false
                            CGetMessageInterface.setSpeechUseInfo("0")
                        }else{
                            textv.text="是"
                            checked=true
                            CGetMessageInterface.setSpeechUseInfo("1")
                        }
                    }
                }
                Text {
                    id:textv
                    x:parent.width/2+5*dp
                    text: qsTr("是")
                    font.pixelSize: config.fontsize
                }
            }

            Rectangle { height: 150*dp; width: 20*dp }
            PushButton{
                width: 120*dp
                height: 40*dp
                y:250*dp
                anchors.right: parent.right
                title: "确认"
                defaultMode1: true
                onReleased: {
                    CGetMessageInterface.connectSpeechMode(serialPort.getText());
                }
            }
        }
    }
}
